#!/bin/bash
# Ensure leftover MD and LVM partitions on the target disk are not
# automatically activated by udev, thus preventing the installer from
# gaining exclusive access to the disk.

set -euo pipefail

# Configure mdadm
if [ ! -e /etc/mdadm.conf.d/nestos-installer.conf ]; then
    mkdir -p /etc/mdadm.conf.d
    cat > /etc/mdadm.conf.d/nestos-installer.conf <<EOF
# Disable MD auto-assembly for nestos-installer
AUTO -all
EOF
fi

# Configure LVM
if ! grep -q nestos-installer /etc/lvm/lvm.conf; then
    cat >> /etc/lvm/lvm.conf <<EOF

# Disable LVM auto-activation for nestos-installer
devices {
        filter = [ "r|.*|" ]
}
EOF
fi
